package com.sjsu.cloudmanager.client;

import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.util.Theme;
import com.extjs.gxt.ui.client.util.ThemeManager;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.Messages;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.sjsu.cloudmanager.client.service.CloudLabService;
import com.sjsu.cloudmanager.client.service.CloudLabServiceAsync;
import com.sjsu.cloudmanager.client.service.CloudUserAdminService;
import com.sjsu.cloudmanager.client.service.CloudUserAdminServiceAsync;
import com.sjsu.cloudmanager.client.ui.LabMainPanel;



/**
 * Entry point classes define <code>onModuleLoad()</code>.
 * <p/>
 * User: ckempaiah
 * Date: 9/28/2011
 */
public class CloudManager implements EntryPoint {
    public static final String CLOUD_LAB_SERVICE = GWT.getModuleBaseURL() + "/cloudmanager/gwt/cloudLabService";
    public static final String USER_ADMIN_SERVICE = GWT.getModuleBaseURL() + "/cloudmanager/gwt/adminUserService";

    public static boolean isExplorer() {
        String test = Window.Location.getPath();
        if (test.indexOf("pages") != -1) {
            return false;
        }
        return true;
    }

    /**
     * The message displayed to the user when the server cannot be reached or
     * returns an error.
     */
    private static final String SERVER_ERROR = "An error occurred while "
            + "attempting to contact the server. Please check your network "
            + "connection and try again.";


    private final Messages messages = GWT.create(Messages.class);


    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {

        CloudLabServiceAsync serviceAsync = (CloudLabServiceAsync) GWT.create(CloudLabService.class);

        CloudUserAdminServiceAsync userAsync = (CloudUserAdminServiceAsync) GWT.create(CloudUserAdminService.class);

        Registry.register(CLOUD_LAB_SERVICE, serviceAsync);
        Registry.register(USER_ADMIN_SERVICE, userAsync);
        Theme.GRAY = new Theme("gray", GXT.MESSAGES.themeSelector_grayTheme(), "gxt-225/css/gxt-gray.css");
        ThemeManager.register(Theme.GRAY);

        GXT.setDefaultTheme(Theme.GRAY,true);

        //RootPanel.get().add(new LabMainPanel());
        RootPanel.get().add(new LabMainPanel());


    }
}
